import java.util.ArrayList;
import java.util.List;

public class Scheme {
  private SchemeType schemeType;

  public Scheme(SchemeType schemeType) {
    this.schemeType = schemeType;
  }

  public void crop(List<List> exList) {
    if (schemeType == SchemeType.THREEONE || schemeType == SchemeType.CUSTOM) {
      for (int i = 3; i < exList.size(); i += 3) {
        exList.remove(i);
        exList.remove(i);
      }
    }
  }

  public void addRestDays(List<List> exList) {
    Ex breakDay = new Ex("break", ExType.REST);
    List<Ex> breakList = new ArrayList<Ex>();
    breakList.add(breakDay);
    if (schemeType == SchemeType.THREEONE) {
      for (int i = 3; i < exList.size(); i += 4) {
        exList.add(i, breakList);
      }
    } else if (schemeType == SchemeType.FIVETWO) {
      for (int i = 5; i < exList.size(); i += 7) {
        exList.add(i, breakList);
        exList.add(i, breakList);
      }
    }
  }

  public void addRestDays(List<List> exList, int startingDay, int... breakDays) {
    Ex restDay = new Ex("break", ExType.REST);
    List<Ex> restList = new ArrayList<Ex>();
    restList.add(restDay);
    for (int i = 0; i < breakDays.length; i++) {
      breakDays[i] -= startingDay;
      if (breakDays[i] < 0) {
        breakDays[i] += 7;
      }
    }
    for (int i = 0; i < exList.size(); i++) {
      for (int y = 0; y < breakDays.length; y++) {
        if (i == breakDays[y]) {
          exList.add(i, restList);
          breakDays[y] += 7;
        }
      }
    }
  }

  public SchemeType getType() {
    return schemeType;
  }
}

